<h1>queryString</h1>

<ul>
<li> <a href="#1">Code</a>
<ul>
<li> <a href="#2">Uses </a>
<li> <a href="#3">Demo</a>
<li> <a href="#4">Code </a>
</ul>
<li> <a href="#5">To do</a>
<li> <a href="#6">Author</a>
</ul>
<p>
The URL of a Penny page contains a little language. This language allows for the
convenient reference of web pages.
</p>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<li><strong> <em>?page</em>              : returns <em>page.html</em>. </strong> <em>?Tag</em>               : returns all pages with a certain <em>Tag</em>.<strong> <em>?Tag1&Tag2&...</em>     : returns all pages with all off <em>Tag1</em> and <em>Tag2</em> and ...
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
</ul>
<li></strong> <em>?page&Tag1&Tag2&tile=X... : returns page, then all the other pages tagged with 
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<ul>
<li>                         </em>Tag1<em> etc. The title of this page is X.                         This is useful for generating a report			 with a header page on top, followed by pages of details.			 Note that if </em>page<em> has </em>Tag1_ etc, then it is only                          printed once.
</ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul></ul>
<p>
At a first approximation, <em>Tags</em> start with upper case and everything is a <em>page</em>.
However, there are exceptions:
</p>


<a name="1"></a><h2>Code</h2>

<a name="2"></a><h3>Uses </h3>
<p>
<a href="?deShell">deShell</a> <a href="?stack">stack</a> <a href="?o">o</a> 
</p>
<a name="3"></a><h3>Demo</h3>
<pre>
 function testQueryString(tagsFile,str,     files,titles,tags,sgat,out) {
     loadTags(tagsFile,files,titles,tags,sgat)
     print queryString1(str,tags,files,titles,sgat,out)
     o(out,"out")
 }
</pre>
<a name="4"></a><h3>Code </h3>
<p>
# stag to tags
</p>
<pre>
 function queryString(tags,files,titles,sgat,out) {
     queryString(ENVIRON["QUERY_STRING"],tags,files,titles,sgat,out) 
 }
 function queryString1(query,tags,files,titles,sgat,out,   \
                       var,used,seen,cats,n,tmp,i,is,title) {
   n = split(query,tmp,"&");
   for(i=1;i&lt;=n;i++) {
        tmp[i] = qprepVar(tmp[i])
        is[i] = qrecognizer(tmp[i])
        if (is[i] == "category") cats++
   }
   for(i=1; i&lt;=n; i++) {
     var = tmp[i];
     if (is[i]=="title")     
         title = qtitle(var);
     if (is[i]=="file")     
         title = title " " qfile(var,tags,1,        seen,used,files,titles,sgat,out);
     if (is[i]=="shortcut") 
         title = title " " qshortcut(var,tags,1,    seen,used,files,titles,sgat,out);
     if (is[i]=="category") 
         title = title " " qcategory(var,tags,cats, seen,used,files,titles,sgat,out);
   } 
   return title; 
 }
 function qprepVar(var) { 
   var = trim(var);
   gsub(/_/,".",var);
   gsub(/\+/," ",var);
   return deShell(var);
 }
 function qrecognizer(var) {
   if (var ~ /^title=/) return "title";
   if (var ~ /^[a-z_0-9]/) {
     if (var ~ /\//     ) return "file";
     if (var ~ /\.html$/) return "file";
     return "shortcut";
   }
   return "category";
 }
 function qtitle(var,  tmp) {
     split(var,tmp,"=")
     return trim(tmp[2])
 }
 function qshortcut(var,tags,needs,seen,used,files,titles,sgat,out) { # shortcut to file 
   var=  (var in files) ? files[var] : tags["NotFound"];
   return qfile(var,tags,needs,seen,used,files,titles,sgat,out);
 }	
 function qfile(var,tags,needs,seen,used,files,titles,sgat,out,   title) { # add file
   title=" ";
   var = (var in titles) ? var : tags["default"];
   if (++used[var] == needs ) 
       if(++seen[var] ==  1) {
           push(out,var);
           title = " " titles[var]; }
   return title;
 }
 function qcategory(var,tags,needs,seen,used,files,titles,sgat,out,     i,n) {#add files from cats
     n =cards(sgat,var);
     for(i=1;i&lt;=n;i++) 
         qfile(sgat[var,i],tags,needs,seen,used,files,titles,sgat,out);
     return var;
 }
</pre>
<a name="5"></a><h2>To do</h2>
<p>
404 error
</p>
<a name="6"></a><h2>Author</h2>
<p>
Tim Menzies
